<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* 
* Module default for frontpage
* @author DANG DINH HUNG
*
*/
class Seller extends Public_Controller
{
	var $task= "";
	public function __construct()
	{
		parent::__construct();
		$this->load->model('seller_m'); 
		
		$this->show_entity->changeStatusOfShowOutOfBid();
		
		$this->seller_m->authorization();
		
		$this->task = $this->uri->segment(3,'');
		$this->data->navigator = $this->_buildMenu();	
		$this->data->phpJS = php2js();
		
		$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/md5.js"."' ></script>");
		$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/seller.js"."' ></script>");	
	//	$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/date.js"."' ></script>");
	}
	
	private function _buildMenu(){
		return $this->seller_m->_buildMenu($this->task);	
	}
/**	
	function test(){
		$this->load->library('email_sender'); 
		$this->email_sender->_sendEmailToAdmin_remindAdminSendEmailToBankReleaseFund( 2836418551 );
	}
**/	
	public function index()
	{
		redirect("seller/my_shows");
		$this->data->record_array = $this->seller_m->index();
		$this->template
			->build('index', $this->data);
	}
	
	function dispute(){
		redirect(site_url('seller'));
	}
	
	function my_account(){
		$this->load->model('account_m'); 
		switch($this->task){
			default:
				$this->data->items = $this->account_m->index();
				$this->template
					->build('account/index', $this->data);
				break;
			case 'edit_information':
				$this->data->items = $this->account_m->index();
				$this->template
					->build('account/edit_information', $this->data);
				break;
			case 'submit_information':
				$this->account_m->submit_information();
				break;
			case 'edit_information_notify':
				$this->template
					->build('account/edit_information_notify', $this->data);
				break;
			case 'change_password':
				$this->data->items = $this->account_m->index();
				$this->template
					->build('account/change_password', $this->data);
				break;
			case 'submit_password':
				$this->account_m->submit_password();
				break;
			case 'change_password_notify':
				$this->template
					->build('account/change_password_notify', $this->data);
				break;
			case 'change_email':
				$this->template
					->build('account/change_email', $this->data);
				break;
			case 'submit_email':
				$this->account_m->submit_email();
				break;
			case 'change_email_notify':
				$this->template
					->build('account/change_email_notify', $this->data);
				break;
		}
	}
	
	function add_show(){
		$this->load->model('addshow_m');
		
		switch($this->task){
			default:
			case 'add':
				$this->data->items = $this->addshow_m->index();
				$this->template->build('addshow/index', $this->data);
				break;
			case 'submit_show':
				$this->addshow_m->submit_show();
				break;
			case 'add_notify':
				$this->template->build('addshow/add_notify', $this->data);
				break;
			case 'cancel_and_create':
				$this->addshow_m->cancel_and_create();
				break;
			case 'edit_show':
				$this->addshow_m->edit_show();
				break;
			case 'preview_show':
				$this->template->build('addshow/preview_show', $this->data);
				break;
			case 'save_show':
				$this->addshow_m->save_show();
				break;
		}		
		 
	}
	
	function my_shows(){
		$this->load->model('myshows_m');
		switch($this->task){
			case 'all_shows':
			default:
				$this->data->items = $this->myshows_m->all_shows();
				break;
			case 'past_shows':
				$this->data->items = $this->myshows_m->past_shows();
				break;
			case 'upcoming_shows':
				$this->data->items = $this->myshows_m->upcoming_shows();
				break;
		}		
		
		$this->template->build('my_shows/index', $this->data);
	}
	
	function search(){
		php2js();
		$this->load->model('myshows_m');
		
		$this->data->items = $this->myshows_m->search();
		$this->template->build('my_shows/index', $this->data);
	}
	
	function show_manage(){
		$USER = $this->user_entity->init('id', $_SESSION['user']['id']);
		$SHOW = $this->show_entity->init('id', intval($this->input->get('show_id',''))) or show_404();
		
		if( $SHOW->getUserCreatedId() != $USER->getId() ){
			show_404();exit();
		}
		
		$this->load->model('showmanage_m');
		
		switch($this->task){
			default:
			case 'view_edit':
				$this->data->items = $this->showmanage_m->view_edit();
				$this->template->build('show_manage/view_edit', $this->data);
				break;
			case 'edit_show':
				$this->data->items = $this->showmanage_m->view_edit();
				$this->template->build('show_manage/edit_show', $this->data);
				break;
			case 'edit_show_notify':
				$this->template->build('show_manage/edit_show_notify', $this->data);
				break;
			case 'bid':
				$this->data->items = $this->showmanage_m->bid();
				$this->template->build('show_manage/bid', $this->data);
				break;
			case 'bid_details':
				$this->data->items = $this->showmanage_m->bid_details();
				$this->template->build('show_manage/bid_details', $this->data);
				break;
			case 'accept_bid':
				$this->showmanage_m->accept_bid();
				break;	
		}
	}
	
	function buyer_information(){
		$this->load->model('account_m'); 
		$this->data->items = $this->account_m->buyer_information();
		$this->template->build('general/buyer_information', $this->data);
	}
	
	function show_details(){
		$this->load->model('showmanage_m');
		$this->data->items = $this->showmanage_m->show_details();
		$this->template->build('general/show_details', $this->data);
	}
	
	
	
	
}